package com.example.h5server.controller;

import com.example.h5server.model.User;
import com.example.h5server.service.LoginAuthService;
import com.example.h5server.service.impl.LoginAuthServiceImpl;
import com.example.h5server.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
//@CrossOrigin(origins = "http://localhost:5218")

@RestController
@RequestMapping("/api")
@Tag(name = "通用webApi")
public class LoginAuthController {
    @Autowired
    private LoginAuthService loginAuthService;

    @PostMapping("/loginByPassword")
    @Operation(summary = "账号密码登录")
    public Result<LoginAuthServiceImpl.LoginResponse> loginByPassword(@RequestParam String username, @RequestParam String password) {
        return loginAuthService.login( username, password );
    }
    // 添加需要鉴权的测试接口

    @SecurityRequirement(name = HttpHeaders.AUTHORIZATION)

    @GetMapping("/profile")
    @Operation(summary = "鉴权的测试接口")
    @SecurityRequirement(name = "bearerAuth")
    public Result<String> getProfile() {

        return Result.success("鉴权的测试信息获取成功");
    }
}
